//
//  FLMBackProfitController.m
//  FLMSuperS
//
//  Created by xiaoyang on 16/9/20.
//  Copyright © 2016年 FaLaoMiaoNetworkTechnologyCo. All rights reserved.
//

#import "FLMBackProfitController.h"
#import "TYTabButtonPagerController.h"
#import "FLMDefaultViewController.h"//详情页面

//当前页为默认

@interface FLMBackProfitController ()<SDCycleScrollViewDelegate,TYPagerControllerDataSource>

@property (nonatomic, strong) SDCycleScrollView          * lunboV; //轮播视图
@property (nonatomic, strong) TYTabButtonPagerController * pagerController;
@property (nonatomic, assign) BOOL         variable;
@property (nonatomic, assign) BOOL         showNavBar;
@property (nonatomic, strong) UIButton                   * sequenceBtn;
@property (nonatomic, strong) UIButton                   * firstBtn;
@property (nonatomic, strong) UIButton                   * secondBtn;




@end

@implementation FLMBackProfitController


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (!_showNavBar) {
        self.navigationController.navigationBarHidden = YES;
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    if (!_showNavBar) {
        self.navigationController.navigationBarHidden = NO;
    }
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    
    _pagerController.view.frame = CGRectMake(0, self.lunboV.bottom+GETSIZE(10), ScreenW, ScreenH-self.lunboV.bottom);


 }




- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"profile_navigation_background"] forBarMetrics:UIBarMetricsDefault];

    //设置导航栏
    // 添加返回按钮
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0,GETSIZE(80),GETSIZE(25))];
    UIButton * img = [[UIButton alloc] initWithFrame:CGRectMake(0,GETSIZE(8),GETSIZE(10),GETSIZE(13))];
    [img setBackgroundImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateNormal];
    [img addTarget:self action:@selector(returnClick) forControlEvents:(UIControlEventTouchUpInside)];
    [view addSubview:img];
    
    UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(GETSIZE(5),GETSIZE(0),GETSIZE(50),GETSIZE( 30))];
    [btn setTitle:@"返回" forState:(UIControlStateNormal)];
    btn.titleLabel.font = [UIFont systemFontOfSize:GETFONTSIZE(18)];
    [btn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [btn addTarget:self action:@selector(returnClick) forControlEvents:(UIControlEventTouchUpInside)];
    [view addSubview:btn];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];

    
    
    self.title = @"高佣返利";
     [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:GETFONTSIZE(18)],
       NSForegroundColorAttributeName:Red}];
    
    
    //添加轮播图
    [self cycleScrollview];
    //横向导航栏
    [self addHengNavigation];
    //条件排序按钮
    [self sequenceButton];
    
    
}


-(void)returnClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark－添加轮播图

//顶部轮播图
- (void)cycleScrollview{
  
    //网络图片实现
    NSArray *imagesURLStrings = @[
                                  @"1",
                                  @"https://ss0.baidu.com/-Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a41eb338dd33c895a62bcb3bb72e47c2/5fdf8db1cb134954a2192ccb524e9258d1094a1e.jpg",
                                  @"http://c.hiphotos.baidu.com/image/w%3D400/sign=c2318ff84334970a4773112fa5c8d1c0/b7fd5266d0160924c1fae5ccd60735fae7cd340d.jpg"
                                  ];
    
    //网络加载图片轮播器
    CGRect frame = CGRectMake(0, 0, ScreenW, GETSIZE(120));
    self.lunboV = [SDCycleScrollView cycleScrollViewWithFrame:frame delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.lunboV.pageControlStyle =   SDCycleScrollViewPageContolStyleNone;
    self.lunboV.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
    [self.view addSubview:self.lunboV];
    
    //加载延迟
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.lunboV.imageURLStringsGroup = imagesURLStrings;
    });
    
    // block监听点击方式
    self.lunboV.clickItemOperationBlock = ^(NSInteger index) {
        NSLog(@">>>>>  %ld", (long)index);
    };
    
    
}

#pragma mark-添加横向导航
-(void)addHengNavigation{
    
    TYTabButtonPagerController * pagerController = [[TYTabButtonPagerController alloc]init];
    
    pagerController.dataSource = self;
//    pagerController.adjustStatusBarHeight = YES;
    pagerController.barStyle = _variable ? TYPagerBarStyleProgressBounceView: TYPagerBarStyleProgressView;
     pagerController.cellSpacing = GETSIZE(12);
    
     pagerController.view.frame = CGRectMake(0, self.lunboV.bottom+GETSIZE(10), ScreenW,ScreenH-self.lunboV.bottom);
    
    if (_showNavBar) {
        pagerController.progressWidth = _variable ? 0 : 36;
    }
    
    
    [self addChildViewController:pagerController];
    [self.view addSubview:pagerController.view];
    _pagerController = pagerController;
    
}

//实现代理方法
#pragma mark - TYPagerControllerDataSource
- (NSInteger)numberOfControllersInPagerController{
    return 5;
}


- (NSString *)pagerController:(TYPagerController *)pagerController titleForIndex:(NSInteger)index{
    return @[@"默认",@"返利率",@"限时抢",@"获利",@"热门"][index];
}


- (UIViewController *)pagerController:(TYPagerController *)pagerController controllerForIndex:(NSInteger)index
{
    if (index == 0) {
     
        [_firstBtn setImage:[UIImage imageNamed:@"活动时间大到小"] forState:UIControlStateNormal];
        [_secondBtn setImage:[UIImage imageNamed:@"活动时间小到大"] forState:UIControlStateNormal];
       
        FLMDefaultViewController * VC = [[FLMDefaultViewController alloc]init];
        VC.index = 0;
        return VC;

    }
    else if (index == 1) {
        
        [_firstBtn setImage:[UIImage imageNamed:@"返利率大到小"] forState:UIControlStateNormal];
        [_secondBtn setImage:[UIImage imageNamed:@"返利率小到大"] forState:UIControlStateNormal];

        
       FLMDefaultViewController * VC = [[FLMDefaultViewController alloc]init];
        VC.index = 1;
        return VC;

    }
    else if (index == 2) {

        [_firstBtn setImage:[UIImage imageNamed:@"活动时间大到小"] forState:UIControlStateNormal];
        [_secondBtn setImage:[UIImage imageNamed:@"活动时间小到大"] forState:UIControlStateNormal];
        
        FLMDefaultViewController * VC = [[FLMDefaultViewController alloc]init];
       VC.index = 2;
        return VC;
    
    }
    else if (index == 3)  {
        
        [_firstBtn setImage:[UIImage imageNamed:@"价格大到小"] forState:UIControlStateNormal];
        [_secondBtn setImage:[UIImage imageNamed:@"价格小到大"] forState:UIControlStateNormal];
 
        FLMDefaultViewController * VC = [[FLMDefaultViewController alloc]init];
        VC.index = 3;
        return VC;
        
    }
    else if (index == 4) {
     
        [_firstBtn setImage:[UIImage imageNamed:@"热度大到小"] forState:UIControlStateNormal];
        [_secondBtn setImage:[UIImage imageNamed:@"热度小到大"] forState:UIControlStateNormal];
        
        FLMDefaultViewController * VC = [[FLMDefaultViewController alloc]init];
        VC.index = 4;
        return VC;
    
    }
    
    return self;
}



#pragma mark-排序按钮
-(void)sequenceButton{
 
    _firstBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _firstBtn.frame = CGRectMake(GETSIZE(30), GETSIZE(50), GETSIZE(140), GETSIZE(40));
//   _firstBtn.backgroundColor = [UIColor cyanColor];
    [_pagerController.view addSubview:_firstBtn];
    
    _secondBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _secondBtn.frame = CGRectMake(ScreenW - GETSIZE(170), GETSIZE(50), GETSIZE(140), GETSIZE(40));
//    _secondBtn.backgroundColor = [UIColor cyanColor];
    [_pagerController.view addSubview:_secondBtn];

}











- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/




@end
